def nextGreaterElement(nums1, nums2):
    res = []
    stack = []
    hash_table = {}
    for num in nums2:
        while (len(stack) != 0) and num > stack[-1]:
            temp = stack.pop()
            hash_table[temp] = num
        stack.append(num)
    while (len(stack) != 0):
        temp = stack.pop()
        hash_table[temp] = -1
    for i in range(len(nums1)):
        res.append(hash_table[nums1[i]])
    return res


nums1 = [4, 1, 2]
nums2 = [1, 3, 4, 2]
print(nextGreaterElement(nums1, nums2))  # [-1, 3, -1]
